import { onMounted, reactive } from 'vue';
import axios from 'axios';

export default function () {
    let dogList = reactive([
        'https://images.dog.ceo/breeds/pembroke/n02113023_16112.jpg',
    ])
    
    async function addADog() {
        try {
            let result = await axios.get('https://dog.ceo/api/breed/pembroke/images/random');
            dogList.push(result.data.message);
        } catch (error) {
            alert(error);
        }
    }

    // hook里用钩子
    onMounted(() => {
        addADog();
    });

    // 向外部提供内容
    return { dogList, addADog };
}